local jw_shenhu = fk.CreateSkill {
    name = "jw_shenhu",
}

Fk:loadTranslationTable {
    ["jw_shenhu"] = "身护",
    [":jw_shenhu"] = "每回合限一次，其他角色受到牌造成的伤害时，你可以受到等量的伤害取消之，然后获得此牌并标记为“创”，随后你可以弃置一张牌选择回复一点体力，或令其摸两张牌。",

    ["shenhu_drwacard"] = "%src 摸两张牌",
    ["shenhu_addhp"] = "回复一点体力",

    ["$jw_shenhu1"] = "谁再上前一步，我教他血溅当场！",
    ["$jw_shenhu2"] = "化身成盾，护卫吾主！",

    ["@@zhoutai_chuang-inhand"] = "创",
}

jw_shenhu:addEffect(fk.DetermineDamageInflicted, {
    anim_type = "defensive",
    can_trigger = function(self, event, target, player, data)
        return player:hasSkill(jw_shenhu.name) and data.to ~= player and data.card and not data.card:isVirtual() and
            data.damage > 0 and player:usedSkillTimes(jw_shenhu.name, Player.HistoryTurn) == 0
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        room:damage {
            from = player,
            to = player,
            damage = data.damage,
            skillName = jw_shenhu.name,
        }
        room:addTableMarkIfNeed(player, "jw_shenhu", data.to.id)
        data:preventDamage()
        room:obtainCard(player, data.card, true, fk.ReasonJustMove, player, jw_shenhu.name, "@@zhoutai_chuang-inhand")
        local card = room:askToDiscard(player, {
            min_num = 1,
            max_num = 1,
            skill_name = jw_shenhu.name,
            prompt = "身护：你可以弃置一张牌，令" .. data.to.id .. "摸两张牌或令自己回复一点体力"
        })
        if #card == 0 then return end
        local all_chs = { "shenhu_drwacard:" .. data.to.id, "shenhu_addhp" }
        local chs = { "shenhu_drwacard:" .. data.to.id, "shenhu_addhp" }
        if not player:isWounded() then
            table.removeOne(chs, "shenhu_addhp")
        end
        local chc = room:askToChoice(player, {
            skill_name = jw_shenhu.name,
            choices = chs,
            all_choices = all_chs,
        })
        if chc == nil then chc = "shenhu_drwacard:" .. data.to.id end
        if chc == "shenhu_drwacard:" .. data.to.id then
            data.to:drawCards(2, jw_shenhu.name)
        else
            room:recover({
                who = player,
                num = 1,
                recoverBy = player,
                skillName = jw_shenhu.name
            })
        end
    end,
})

return jw_shenhu
